package at.fhooe.engine.event;

import at.fhooe.engine.event.events.Event;

public class EventManager {
	
	private DispatchStrategy m_dispatchStrategy;
	private ListenerStrategy m_listenerStrategy;
	
	public EventManager(DispatchStrategy dispatchStrategy, ListenerStrategy listenerStrategy) {
		m_listenerStrategy = listenerStrategy;
		m_dispatchStrategy = dispatchStrategy;
		m_dispatchStrategy.setListenerStrategy(m_listenerStrategy);
	}
	
	public synchronized void update() {
		m_dispatchStrategy.update();
	}
	
	public synchronized void dispatchEvent(Event event) {
		m_dispatchStrategy.dispatchEvent(event);
	}
	
	public synchronized void removeListener(EventListener eventListener, String eventType) {
		m_listenerStrategy.removeListener(eventListener, eventType);
	}
	
	public synchronized void addListener(EventListener eventListener, String eventType) {
		m_listenerStrategy.addListener(eventListener, eventType);
	}

	public void removeAllListeners() {
		m_listenerStrategy.removeAllListeners();
	}
	
	public void setListenerStrategy(ListenerStrategy listenerStrategy) {
		m_listenerStrategy = listenerStrategy;
		m_dispatchStrategy.setListenerStrategy(m_listenerStrategy);
	}
	
	public void setDispatchStrategy(DispatchStrategy dispatchStrategy) {
		m_dispatchStrategy = dispatchStrategy;
		m_dispatchStrategy.setListenerStrategy(m_listenerStrategy);
	}
	
	public void clearEventsForDispatch() {
		m_dispatchStrategy.clearEventsForDispatch();
	}
}
